package cn.imvc.util;

import java.util.Random;

/**
 * 随机生成唯一id
 * 
 * @author nvoyager
 *
 */
public class RandomId {
	private static Random random;
	private static String table;

	static {
		random = new Random();
		table = "0123456789";
	}

	public static String randomId(long id) {
		id=id % 10000000000L;
		String ret = null;
		String num = String.format("%010d", id);

		int key = random.nextInt(10);
		int seed = random.nextInt(100);

		Caesar caesar = new Caesar(table, seed);
		num = caesar.encode(key, num);
		ret = num + String.format("%01d", key) + String.format("%02d", seed);
		return ret;
	}

	public static String randomCheckCode(long id) {
		String ret = null;
		String num = String.format("%09d", id);

		int key = random.nextInt(10);
		int seed = random.nextInt(100);

		Caesar caesar = new Caesar(table, seed);
		num = caesar.encode(key, num);
		ret = num + String.format("%01d", key) + String.format("%02d", seed);
		return ret;
	}

	public static String serialNumber() {
		return null;
	}

}
